package com.mall.web.controller.goods.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.goods.model.dto.GoodsRecommendDto;
import com.mall.goods.model.vo.GoodsRecommendVo;
import com.mall.goods.service.IGoodsRecommendService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 商品推荐Controller
 */
@RestController
@RequestMapping("/admin/goods/goodsRecommend")
public class AdminGoodsRecommendController extends BaseController
{
    @Autowired
    private IGoodsRecommendService goodsRecommendService;

    /**
     * 查询商品推荐列表GoodsRecommendMapper
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsRecommendDto goodsRecommendDto)
    {
        startPage();
        List<GoodsRecommendVo> list = goodsRecommendService.selectGoodsRecommendList(goodsRecommendDto);
        return getDataTable(list);
    }

    /**
     * 导出商品推荐列表
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:export')")
    @Log(title = "商品推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsRecommendDto goodsRecommendDto)
    {
        List<GoodsRecommendVo> list = goodsRecommendService.selectGoodsRecommendList(goodsRecommendDto);
        ExcelUtil<GoodsRecommendVo> util = new ExcelUtil<GoodsRecommendVo>(GoodsRecommendVo.class);
        util.exportExcel(response, list, "商品推荐数据");
    }

    /**
     * 获取商品推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsRecommendService.selectGoodsRecommendById(id));
    }

    /**
     * 新增商品推荐
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:add')")
    @Log(title = "商品推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsRecommendDto goodsRecommendDto)
    {
        return toAjax(goodsRecommendService.insertGoodsRecommend(goodsRecommendDto));
    }

    /**
     * 修改商品推荐
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:edit')")
    @Log(title = "商品推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsRecommendDto goodsRecommendDto)
    {
        return toAjax(goodsRecommendService.updateGoodsRecommend(goodsRecommendDto));
    }

    /**
     * 删除商品推荐
     */
    @PreAuthorize("@ss.hasPermi('goods:recommend:remove')")
    @Log(title = "商品推荐", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsRecommendService.deleteGoodsRecommendByIds(ids));
    }
}
